package com.qdev.apps.core.setup.sitemesh;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet;

import freemarker.template.SimpleHash;
import freemarker.template.Template;
import freemarker.template.TemplateModel;

/**
 * Servlet that extendss FreemarkerDecoratorServlet, we can use this to put some
 * util into hash.
 * 
 * @author Quake Wang
 * @since 2004-7-15
 * @version $Revision: 1.2 $
 */
public class DefaultFreemarkerDecoratorServlet extends FreemarkerDecoratorServlet {

    protected boolean preTemplateProcess(HttpServletRequest request, HttpServletResponse response, Template template,
            TemplateModel templateModel) throws ServletException, IOException {
        boolean result = super.preTemplateProcess(request, response, template, templateModel);
        template.setEncoding("UTF-8");
        SimpleHash hash = (SimpleHash) templateModel;
        hash.put("req", request);
        hash.put("res", response);
        return result;
    }
}